--screen1 = FIELD

module(..., package.seeall)

local imgPath = "images/"

new = function ( params )
	
	local ui = require ( "ui" )
	
	local localGroup = display.newGroup()
	
		---syed Collecting Gem's Bar
			--common vars
			gemCountFontSize = 25;
		
			--fire gem bar
			barWidth = 100;
			nextWidth = 0;
			restWidth = 0;
			adjustWidth = 2;
			isFireClickable = true;
			fireGemCountX = 30;
			fireGemCountY = 470;
			

			local timeBar = display.newRect( 0, 0, 100, 10 ) 
			
			--fire bar border
			local bdr = display.newRect( 0, 0, barWidth+2, 10 )
			bdr:setReferencePoint(display.BottomLeftReferencePoint) 
			bdr.strokeWidth = 1
			bdr:setFillColor(255, 255, 0)
			bdr:setStrokeColor(0, 222, 222)

			--fire bar filling
			local progBarGroup = display.newGroup();
			progBarGroup.x = -50;
			progBarGroup.y = -190;
			progBarGroup:insert(bdr)
			progBarGroup:insert(timeBar)
			progBarGroup.xScale = 0.8;
			progBarGroup.yScale = 0.8;

			--common
			local function putPrgBar(xPos,yPos, bar)
				progBarGroup.x = xPos;
				progBarGroup.y = yPos;	
				bar.width = 20;
				bar:setReferencePoint(display.BottomLeftReferencePoint) 
				bar.x = 0 
			end
			
			--common
			local function putPrgBar2(xPos,yPos, grp, bar)
				grp.x = xPos;
				grp.y = yPos;	
				bar.width = 20;
				bar:setReferencePoint(display.BottomLeftReferencePoint) 
				bar.x = 0 
			end
			
			
			--system.getTime();********* get time since game started
			
			--make the bar progress
			 local loseTime = {}
			 function loseTime:timer( event )
				local count = event.count
				-- print( "Table listener called " .. count .. " time(s)" )
				-- if count >= 3 then
					-- timer.cancel( event.source ) -- after 3rd invocation, cancel timer
				-- end

				nextWidth = timeBar.width + 5; 
				if (nextWidth > barWidth) then 
					--calculate unfilled width
					restWidth = barWidth - timeBar.width;
					nextWidth = timeBar.width + restWidth + adjustWidth;
					airGemCount.text = airGemCount.text + 1
					timer.cancel( event.source )
				end;
				timeBar.width = nextWidth; 
				
				timeBar:setReferencePoint(display.BottomLeftReferencePoint) 
				timeBar.x = 0 
			 end		
			--eo fire gem bar
			
			--water gem bar, etc.. settings
			btWaterX, btWaterY = 85, 270;
			btWater_xScale, btWater_yScale = 0.05 , 0.05
			isWaterClickable = true;
			waterGemCountX, waterGemCountY = 80, 470;
			imgWaterGemCountX, imgWaterGemCountY = 70, 450;
			imgWaterGemCount_xScale, imgWaterGemCount_yScale = 0.05, 0.05;
			waterProgBarGroupX, waterProgBarGroupY = 50, 250;
			waterBarWidth = 100;
			waterNextWidth = 0;
			waterRestWidth = 0;
			waterAdjustWidth = 2;
			local waterTimeBar = display.newRect( 0, 0, 100, 10 ) 
						
			--water gem bar border
			local waterBdr = display.newRect( 0, 0, waterBarWidth+2, 10 )
			waterBdr:setReferencePoint(display.BottomLeftReferencePoint) 
			waterBdr.strokeWidth = 1
			waterBdr:setFillColor(255, 255, 0)
			waterBdr:setStrokeColor(0, 222, 222)

			--water gem bar group (filling)
			local waterProgBarGroup = display.newGroup();
			waterProgBarGroup.x = -50;
			waterProgBarGroup.y = -190;
			waterProgBarGroup:insert(waterBdr)
			waterProgBarGroup:insert(waterTimeBar)
			waterProgBarGroup.xScale = 0.8;
			waterProgBarGroup.yScale = 0.8;
			
			--eo water gem bar
			
			--air gem bar, etc.. settings
			btAirX, btAirY = 185, 170;
			btAir_xScale, btAir_yScale = 1 , 1
			isAirClickable = true;
			airGemCountX, airGemCountY = 80, 470;
			imgAirGemCountX, imgAirGemCountY = 180, 450;
			imgAirGemCount_xScale, imgAirGemCount_yScale = 0.05, 0.05;
			airProgBarGroupX, airProgBarGroupY = 170, 160;
			airProgBarGroup_xScale, airProgBarGroup_yScale = 1, 1
			airBarWidth = 100;
			airNextWidth = 0;
			airRestWidth = 0;
			airAdjustWidth = 2;
			local airTimeBar = display.newRect( 0, 0, 100, 10 ) 
						
			--air gem bar border
			local airBdr = display.newRect( 0, 0, airBarWidth+2, 10 )
			airBdr:setReferencePoint(display.BottomLeftReferencePoint) 
			airBdr.strokeWidth = 1
			airBdr:setFillColor(255, 255, 0)
			airBdr:setStrokeColor(0, 222, 222)

			--air gem bar group (filling)
			local airProgBarGroup = display.newGroup();
			airProgBarGroup.x = -150;
			airProgBarGroup.y = -190;
			airProgBarGroup:insert(airBdr)
			airProgBarGroup:insert(airTimeBar)
			airProgBarGroup.xScale = airProgBarGroup_xScale;
			airProgBarGroup.yScale = airProgBarGroup_yScale;			
			--eo air gem bar
			
			--earth gem bar, etc.. settings
			btEarthX, btEarthY = 185, 270;
			btEarth_xScale, btEarth_yScale = 0.3 , 0.3
			isEarthClickable = true;
			earthGemCountX, earthGemCountY = 80, 470;
			imgEarthGemCountX, imgEarthGemCountY = 120, 450;
			imgEarthGemCount_xScale, imgEarthGemCount_yScale = 0.05, 0.05;
			earthProgBarGroupX, earthProgBarGroupY = 170, 260;
			earthProgBarGroup_xScale, earthProgBarGroup_yScale = 1, 1
			earthBarWidth = 100;
			earthNextWidth = 0;
			earthRestWidth = 0;
			earthAdjustWidth = 2;
			local earthTimeBar = display.newRect( 0, 0, 100, 10 ) 
						
			--earth gem bar border
			local earthBdr = display.newRect( 0, 0, earthBarWidth+2, 10 )
			earthBdr:setReferencePoint(display.BottomLeftReferencePoint) 
			earthBdr.strokeWidth = 1
			earthBdr:setFillColor(255, 255, 0)
			earthBdr:setStrokeColor(0, 222, 222)

			--earth gem bar group (filling)
			local earthProgBarGroup = display.newGroup();
			earthProgBarGroup.x = -150;
			earthProgBarGroup.y = -190;
			earthProgBarGroup:insert(earthBdr)
			earthProgBarGroup:insert(earthTimeBar)
			earthProgBarGroup.xScale = earthProgBarGroup_xScale;
			earthProgBarGroup.yScale = earthProgBarGroup_yScale;			
			--eo earth gem bar
			
	---eo syed
	
	------------------
	-- Display Objects
	------------------
	
	local background = display.newImage( "background1.png" )
	local title      = display.newText( "- FIELD -", 0, 0, native.systemFontBold, 16 )
	
	----------syed
	 --level text
	local level      = display.newText( "LV. 43", 10, 35, native.systemFontBold, 13 )

	 -- level bar
	local myRectangleInner = display.newRect(11, 51, 35, 4)
	myRectangleInner.strokeWidth = 0
	myRectangleInner:setFillColor(255, 255, 0)
	myRectangleInner:setStrokeColor(0, 222, 222)

	local myRectangle = display.newRect(10, 50, 50, 6)
	myRectangle.strokeWidth = 1.5
	myRectangle:setFillColor(255, 0 , 0)
	myRectangle:setStrokeColor(0, 0, 0)

	 -- coin
 	local imgCoin = display.newImage( imgPath .. "coin.png" )
	imgCoin.x = 20
	imgCoin.y = 68
	
	 -- coin text
	local txtCoin = display.newText( "20", 35, 62, native.systemFontBold, 11 )

	 --energy text
	local level      = display.newText( "E. 23/25", 260, 35, native.systemFontBold, 13 )

	 -- energy bar
	local myRectangleInner2 = display.newRect(261, 51, 35, 4)
	myRectangleInner2.strokeWidth = 0
	myRectangleInner2:setFillColor(255, 255, 0)
	myRectangleInner2:setStrokeColor(0, 222, 222)

	local myRectangle2 = display.newRect(260, 50, 50, 6)
	myRectangle2.strokeWidth = 1.5
	myRectangle2:setFillColor(255, 0 , 0)
	myRectangle2:setStrokeColor(0, 0, 0)
	
	--syed gem count labels
	--fire
 	local imgFireGemCount = display.newImage( imgPath .. "fireButton.png" )
	local fireGemCount = display.newText( "0", 0, 0, native.systemFontBold, gemCountFontSize )
	imgFireGemCount.x = 20
	imgFireGemCount.y = 450
	--water
 	local imgWaterGemCount = display.newImage( imgPath .. "waterButton.png" )
	waterGemCount = display.newText( "0", 0, 0, native.systemFontBold, gemCountFontSize )
	imgWaterGemCount.x, imgWaterGemCount.y = imgWaterGemCountX, imgWaterGemCountY
	imgWaterGemCount.xScale , imgWaterGemCount.yScale = imgWaterGemCount_xScale, imgWaterGemCount_yScale;
	waterGemCount.x, waterGemCount.y = waterGemCountX, waterGemCountY;
	--earth
 	local imgEarthGemCount = display.newImage( imgPath .. "earthButton_128.png" )
	local earthGemCount = display.newText( "0", 0, 0, native.systemFontBold, gemCountFontSize )
	imgEarthGemCount.x, imgEarthGemCount.y = 120, 450
	imgEarthGemCount.xScale , imgEarthGemCount.yScale = 0.3 , 0.3
	earthGemCount.x, earthGemCount.y = 120 , 470
	--air
 	local imgAirGemCount = display.newImage( imgPath .. "airButton_48.png" )
	airGemCount = display.newText( "0", 0, 0, native.systemFontBold, gemCountFontSize )
	imgAirGemCount.x, imgAirGemCount.y = 180, 450
	imgAirGemCount.xScale , imgAirGemCount.yScale = 0.9 , 0.9
	airGemCount.x, airGemCount.y = 190 , 470
	
	--eo syed gem count labels

	
	--display.newRect( [parentGroup,] left, top, width, height )
	----------eo syed
	
	------------------
	-- Link
	------------------
	
	local goBlog = function ( event )
		if event.phase == "ended" then
			system.openURL( "http://rauberlabs.blogspot.com/" )
		end
	end
	--
	title:addEventListener( "touch", goBlog )
	
	--====================================================================--
	-- BUTTONS
	--====================================================================--
	
	------------------
	-- Functions
	------------------
			--syed common functions
			function updateCollectionBar(grp,bar,labelCnt)
				isWaterClickable = false; --button not clickable until finish collecting gem
				waterNextWidth = bar.width + 5; 
				if (waterNextWidth > waterBarWidth) then 
					waterNextWidth = waterBarWidth + waterAdjustWidth;
					grp.x, grp.y = -100, -100; --make the bar
					tossGem("water",labelCnt);
					timer.cancel(gameWaterTimer);
					--labelCnt.text = labelCnt.text + 1
					isWaterClickable = true; --now can collect gem
				end;
								
				bar.width = waterNextWidth; 
				
				bar:setReferencePoint(display.BottomLeftReferencePoint) 
				bar.x = 0
			end
			
			function updateAirCollectionBar(grp,bar,labelCnt)
				isAirClickable = false; --button not clickable until finish collecting gem
				airNextWidth = bar.width + 5; 
				if (airNextWidth > airBarWidth) then 
					airNextWidth = airBarWidth + airAdjustWidth;
					grp.x, grp.y = -100, -100; --make the bar
					tossGem("air",labelCnt);
					timer.cancel(gameAirTimer);
					--labelCnt.text = labelCnt.text + 1
					isAirClickable = true; --now can collect gem
				end;
								
				bar.width = airNextWidth; 
				
				bar:setReferencePoint(display.BottomLeftReferencePoint) 
				bar.x = 0
			end
			
			function updateEarthCollectionBar(grp,bar,labelCnt)
				isEarthClickable = false; --button not clickable until finish collecting gem
				earthNextWidth = bar.width + 5; 
				if (earthNextWidth > earthBarWidth) then 
					earthNextWidth = earthBarWidth + earthAdjustWidth;
					grp.x, grp.y = -100, -100; --make the bar
					tossGem("earth",labelCnt);
					timer.cancel(gameEarthTimer);
					--labelCnt.text = labelCnt.text + 1
					isEarthClickable = true; --now can collect gem
				end;
								
				bar.width = earthNextWidth; 
				
				bar:setReferencePoint(display.BottomLeftReferencePoint) 
				bar.x = 0
			end
			
			local function removeObject( object )
				object:removeSelf()
				obj = nil   -- nil out original reference (upvalue)
			end
			
			function increaseCount(elem)
				elem.text = elem.text + 1
			end

			function tossGem(elem,labelCnt)
				if (elem == "water") then
					--local imgGemToss = display.newImage( imgPath .. "earthButton_128.png" )
					local imgGemToss = display.newImage( imgPath .. "waterButton.png" )
					imgGemToss.x, imgGemToss.y = 90, 270
					imgGemToss.xScale, imgGemToss.yScale = 0.05, 0.05
					imgGemToss.alpha = 0.5
					--transition.to( imgGemToss, { time=200, alpha=0.1, } )
					transition.to( imgGemToss, { time=200, delay=0, x=80, y=240 } )
					transition.to( imgGemToss, { time=250, delay=200, x=75, y=310 } )
					transition.to( imgGemToss, { time=500, delay=1000, x=70, y=450, transition = easing.inOutExpo, onComplete=removeObject } )
					timer.performWithDelay( 1500, function() increaseCount(labelCnt); end, 1 );
					--timer.performWithDelay(200, function() listenerFunction(arg1, arg2, arg3); end);
				end
				if (elem == "air") then
					--local imgGemToss = display.newImage( imgPath .. "earthButton_128.png" )
					local imgGemToss = display.newImage( imgPath .. "airButton_48.png" )
					imgGemToss.x, imgGemToss.y = btAirX, btAirY
					imgGemToss.xScale, imgGemToss.yScale = 1, 1
					imgGemToss.alpha = 0.5
					transition.to( imgGemToss, { time=200, delay=0, x=btAirX-10, y=btAirY-30 } )
					transition.to( imgGemToss, { time=250, delay=200, x=btAirX-25, y=btAirY+40 } )
					transition.to( imgGemToss, { time=500, delay=1000, x=imgAirGemCountX, y=imgAirGemCountY, transition = easing.inOutExpo, onComplete=removeObject } )
					timer.performWithDelay( 1500, function() increaseCount(labelCnt); end, 1 );
				end
				if (elem == "earth") then
					local imgGemToss = display.newImage( imgPath .. "earthButton_128.png" )
					imgGemToss.x, imgGemToss.y = btEarthX, btEarthY
					imgGemToss.xScale, imgGemToss.yScale = btEarth_xScale, btEarth_yScale
					imgGemToss.alpha = 0.5
					transition.to( imgGemToss, { time=200, delay=0, x=btEarthX-10, y=btEarthY-30 } )
					transition.to( imgGemToss, { time=250, delay=200, x=btEarthX-25, y=btEarthY+40 } )
					transition.to( imgGemToss, { time=500, delay=1000, x=imgEarthGemCountX, y=imgEarthGemCountY, transition = easing.inOutExpo, onComplete=removeObject } )
					timer.performWithDelay( 1500, function() increaseCount(labelCnt); end, 1 );
				end
			end
			-- eo syed common functions

	local bt01t = function ( event ) -- fire button
		if event.phase == "release" then
			putPrgBar(50,190,timeBar);
			--gameTimer = timer.performWithDelay(100,loseTime, 0 )
			timer.performWithDelay( 100, loseTime, 0 );
		end
	end
	--	
	local btWatert = function ( event ) -- water button
		if event.phase == "release" then
			if isWaterClickable == true then
				putPrgBar2(waterProgBarGroupX,waterProgBarGroupY,waterProgBarGroup,waterTimeBar);
				--gameTimer = timer.performWithDelay(100,collectGemTime, 0 )
				gameWaterTimer = timer.performWithDelay(100, function() updateCollectionBar(waterProgBarGroup, waterTimeBar,waterGemCount); end, 0 )
				--gameTimer = timer.performWithDelay(100,loseTime, 0 )
				--timer.performWithDelay( 100, loseTime, 0 );
				--timer.performWithDelay(200, function() listenerFunction(arg1, arg2, arg3); end);
			end
		end
	end
	--
	local btAirt = function ( event ) -- air button
		if event.phase == "release" then
			if isAirClickable == true then
				putPrgBar2(airProgBarGroupX,airProgBarGroupY,airProgBarGroup,airTimeBar);
				gameAirTimer = timer.performWithDelay(100, function() updateAirCollectionBar(airProgBarGroup, airTimeBar,airGemCount); end, 0 )
			end
		end
	end
	--
	local btEartht = function ( event ) -- earth button
		if event.phase == "release" then
			if isEarthClickable == true then
				putPrgBar2(earthProgBarGroupX,earthProgBarGroupY,earthProgBarGroup,earthTimeBar);
				gameEarthTimer = timer.performWithDelay(100, function() updateEarthCollectionBar(earthProgBarGroup, earthTimeBar,earthGemCount); end, 0 )
			end
		end
	end
	--
	local bt02t = function ( event )
		if event.phase == "release" then
			director:changeScene( "lab", "overFromRight" )
		end
	end
	--
	local btInventoryt = function ( event )
		if event.phase == "release" then
			local parameters = {p1="some text", p2="some more text"}
			director:changeScene( parameters, "inventory", "moveFromTop" )
		end
	end
	--
	local bt04t = function ( event )
		if event.phase == "release" then
			director:changeScene( "inventory", "overFromBottom" )
		end
	end
	--
	local bt05t = function ( event )
		if event.phase == "release" then
			director:changeScene( "inventory", "flip" )
		end
	end
	--
	local bt06t = function ( event )
		if event.phase == "release" then
			director:changeScene( "inventory", "downFlip" )
		end
	end
	--
	local bt07t = function ( event )
		if event.phase == "release" then
			director:changeScene( "inventory", "fade" )
		end
	end
	--
	local bt08t = function ( event )
		if event.phase == "release" then
			director:changeScene( "inventory", "crossfade" )
		end
	end
	
	------------------
	-- UI Objects
	------------------
	
	local bt01 = ui.newButton{
					default = imgPath .. "fireButton.png",
					over = imgPath .. "fireButton.png",
					onEvent = bt01t,
					id = "bt01"
	}
	--
	local btWater = ui.newButton{
					default = imgPath .. "waterButton.png",
					over = imgPath .. "waterButton_24.png",
					onEvent = btWatert,
					id = "btWater"
	}
	--
	local btAir = ui.newButton{
					default = imgPath .. "airButton_48.png",
					over = imgPath .. "airButton_48.png",
					onEvent = btAirt,
					id = "btAir"
	}
	--
	local btEarth = ui.newButton{
					default = imgPath .. "earthButton_128.png",
					over = imgPath .. "earthButton_128.png",
					onEvent = btEartht,
					id = "btEarth"
	}
	--
	local bt02 = ui.newButton{
					default = imgPath ..  "arrow_right_48.png",
					over = imgPath ..  "arrow_right_48.png",
					onEvent = bt02t,
					id = "bt02"
	}
	--
	local btInventory = ui.newButton{
					default = imgPath ..  "inventory_72.png",
					over = imgPath ..  "inventory_72.png",
					onEvent = btInventoryt,
					id = "btInventory"
	}
--[[
	--
	local bt04 = ui.newButton{
					default = "bt_overFromBottom.png",
					over = "bt_overFromBottom.png",
					onEvent = bt04t,
					id = "bt04"
	}
	--
	local bt05 = ui.newButton{
					default = "bt_flip.png",
					over = "bt_flip.png",
					onEvent = bt05t,
					id = "bt05"
	}
	--
	local bt06 = ui.newButton{
					default = "bt_downFlip.png",
					over = "bt_downFlip.png",
					onEvent = bt06t,
					id = "bt06"
	}
	--
	local bt07 = ui.newButton{
					default = "bt_fade.png",
					over = "bt_fade.png",
					onEvent = bt07t,
					id = "bt07"
	}
	--
	local bt08 = ui.newButton{
					default = "bt_crossfade.png",
					over = "bt_crossfade.png",
					onEvent = bt08t,
					id = "bt08"
	}
	--]]
		
	--====================================================================--
	-- POPUP
	--====================================================================--
	
	------------------
	-- Image
	------------------
	
	local btPopUp = display.newImage( imgPath .. "missionButton.png" )
	
	------------------
	-- On Close
	------------------
	
	local popClosed_old = function ()
		--
		local fxTime = 200
		--
		transition.to( bt01, { alpha=0, time=fxTime, delay=100 } )
		transition.to( bt02, { alpha=0, time=fxTime, delay=200 } )
		transition.to( btInventory, { alpha=0, time=fxTime, delay=300 } )
		transition.to( bt04, { alpha=0, time=fxTime, delay=400 } )
		transition.to( bt05, { alpha=0, time=fxTime, delay=500 } )
		transition.to( bt06, { alpha=0, time=fxTime, delay=600 } )
		transition.to( bt07, { alpha=0, time=fxTime, delay=700 } )
		transition.to( bt08, { alpha=0, time=fxTime, delay=800 } )
		--
		transition.to( bt01, { alpha=1, time=fxTime, delay=fxTime*2+100 } )
		transition.to( bt02, { alpha=1, time=fxTime, delay=fxTime*2+200 } )
		transition.to( btInventory, { alpha=1, time=fxTime, delay=fxTime*2+300 } )
		transition.to( bt04, { alpha=1, time=fxTime, delay=fxTime*2+400 } )
		transition.to( bt05, { alpha=1, time=fxTime, delay=fxTime*2+500 } )
		transition.to( bt06, { alpha=1, time=fxTime, delay=fxTime*2+600 } )
		transition.to( bt07, { alpha=1, time=fxTime, delay=fxTime*2+700 } )
		transition.to( bt08, { alpha=1, time=fxTime, delay=fxTime*2+800 } )
		--
	end

	local popClosed = function ()
		local fxTime = 200
	end

	------------------
	-- Listener
	------------------
	
	local btPopUpt = function ( event )
		if event.phase == "ended" then
			director:openPopUp( "mission_popup", popClosed )
		end
	end
	
	--====================================================================--
	-- PARAMETERS
	--====================================================================--
	
	------------------
	-- Image
	------------------
	
	local btParameters = display.newImage( "bt_parameters.png" )
	
	------------------
	-- Listener
	------------------
	
	local btParameterst = function ( event )
		if event.phase == "ended" then
			director:changeScene( { label="Sending Parameters", reload=true } , "screen2", "fade", "white" )
		end
	end
	
	--====================================================================--
	-- INITIALIZE
	--====================================================================--
	
	local initVars = function ()
		
		------------------
		-- Inserts
		------------------
		
		localGroup:insert( background )
		--localGroup:insert( title )
		localGroup:insert( bt01 )
		localGroup:insert( bt02 )
		localGroup:insert( imgFireGemCount )
		localGroup:insert( fireGemCount )
		localGroup:insert( imgWaterGemCount )
		localGroup:insert( waterGemCount )
		localGroup:insert( imgEarthGemCount )
		localGroup:insert( earthGemCount )		
		localGroup:insert( imgAirGemCount )
		localGroup:insert( airGemCount )		
		
		--localGroup:insert( btInventory )
		--localGroup:insert( bt04 )
		--localGroup:insert( bt05 )
		--localGroup:insert( bt06 )
		--localGroup:insert( bt07 )
		--localGroup:insert( bt08 )
		--localGroup:insert( btSlide )
		--localGroup:insert( btPopUp )
		--localGroup:insert( btParameters )
		
		------------------
		-- Positions
		------------------
		
		title.x = 160
		title.y = 20
		--
		bt01.x = 85
		bt01.y = 170
		--
		btWater.x = btWaterX
		btWater.y = btWaterY
		btWater.xScale , btWater.yScale = btWater_xScale , btWater_yScale
		--
		btAir.x = btAirX
		btAir.y = btAirY
		btAir.xScale , btAir.yScale = btAir_xScale , btAir_yScale
		--
		btEarth.x = btEarthX
		btEarth.y = btEarthY
		btEarth.xScale , btEarth.yScale = btEarth_xScale , btEarth_yScale
		--
		bt02.x = 290
		bt02.y = 200
		--
		btInventory.x = 160
		btInventory.y = 100
		--
		btPopUp.x = 50
		btPopUp.y = 350
		btPopUp.xScale = -0.6
		btPopUp.yScale = 0.6
		--
		btParameters.x = -160
		btParameters.y = -400
		--
		fireGemCount.x = fireGemCountX
		fireGemCount.y = fireGemCountY

--[[	
		--
		bt04.x = 240
		bt04.y = 130
		--
		bt05.x = 85
		bt05.y = 190
		--
		bt06.x = 240
		bt06.y = 190
		--
		bt07.x = 85
		bt07.y = 250
		--
		bt08.x = 240
		bt08.y = 250
		--]]
		
		------------------
		-- Colors
		------------------
		
		title:setTextColor( 255,255,255 )
		
		------------------
		-- Listeners
		------------------
		
		btPopUp:addEventListener ( "touch" , btPopUpt )
		btParameters:addEventListener ( "touch" , btParameterst )
		
	end
		
	------------------
	-- Initiate variables
	------------------
	
	initVars()
	
	--initProgressBar()
	
	------------------
	-- MUST return a display.newGroup()
	------------------
	
	return localGroup
	
end
